// 合并复用原则
// Composite Reuse Principle, CRP
// 
// 这里用一个司机开车的例子来解释什么是合并复用原则
//

#pragma once

#include <iostream>

/// @brief 汽车抽象类 虚基类
class Car
{
public:
	Car() = default;
	virtual ~Car() {}

	virtual void run() = 0;

};

/// @brief 假设有宝马车开
class BMW : public Car
{
public:
	BMW() = default;
	virtual ~BMW() {}

	virtual void run() {
		std::cout << "drive " << name << " car." << std::endl;
	}

private:
	std::string name = "BMW";

};

/// @brief 假设有大众车开
class Volkswagen : public Car
{
public:
	Volkswagen() = default;
	virtual ~Volkswagen() {}

	virtual void run() {
		std::cout << "drive " << name << " car." << std::endl;
	}

private:
	std::string name = "Volkswagen";

};

/// @brief 司机类
class Drivers
// 司机想要开多种车咋办呢？
//
{
public:
	Drivers() = default;
	~Drivers() = default;
	/*~Drivers() {
		if (this->car_ != NULL)
			delete this->car_;
	}*/

	void setCarType(Car* car) {
		this->car_ = car;
	}

	void driverCar() {
		this->car_->run();

		if (car_ != nullptr)
			delete car_;
	}

private:
	Car* car_;
};
